//登陆的数据
const LoginArr = [{
        username: 'admin',
        pwd: 123456,
        name: '小明',
        rule: '管理员',
        tel: 13333333333,
        address: '北京 昌平',
        sex: '男',
        age: 22,
        token: 'eyJhbGciOiJIUzUxMiJ9.eyJ1c2VySWQiOiJhZG1pbiIsInVzZXJOYW1lIjoiYWRtaW4iLCJvcmdDb2RlIjoiMzUwMDAiLCJkZXB0Q29kZSI6IjM1MDAwIiwiYXVkIjoiYWRtaW4iLCJpc3MiOiJhZG1pbiIsImV4cCI6MTU5MzUzNTU5OH0.0pJAojRtT5lx6PS2gH_Q9BmBxeNlgBL37ABX22HyDlebbr66cCjVYZ0v0zbLO_9241FX9-FZpCkEqE98MQOyWw'
    },
    {
        username: 'user',
        pwd: 123456,
        name: '小红',
        rule: '用户',
        tel: 13333333333,
        address: '北京 昌平',
        sex: '女',
        age: 20,
        token: 'eyJhbGciOiJIUzUxMiJ9.eyJ1c2VySWQiOiJhZG1pbiIsInVzZXJOYW1lIjoiYWRtaW4iLCJvcmdDb2RlIjoiMzUwMDAiLCJkZXB0Q29kZSI6IjM1MDAwIiwiYXVkIjoiYWRtaW4iLCJpc3MiOiJhZG1pbiIsImV4cCI6MTU5MzUzNTU5OH0'
    },
]

export default {
    getUserData: config => {
        const { token } = JSON.parse(config.body)
        var obj = LoginArr.find(item => {
            return item.token == token
        })
        return {
            code: 200,
            msg: '获取用户信息成功',
            data: obj
        }
    },
    loginData: config => {
        const { username, pwd } = JSON.parse(config.body)
        var obj = LoginArr.find(item => {
            return item.username == username
        })
        var pwdTrue = LoginArr.find(item => {
            return item.username == username && item.pwd == pwd
        })
        if (!obj) {
            return {
                code: 201,
                msg: '账号不存在',
                data: null
            }
        } else if (!pwdTrue) {
            return {
                code: 201,
                msg: '密码错误',
                data: null
            }
        } else {
            return {
                code: 200,
                msg: '登陆成功',
                data: obj.token
            }
        }
    },
    modifyLogin: config => {
        const { username, pwd, phone } = JSON.parse(config.body)
        console.log(config.body);
        var obj = LoginArr.find(item => {
            return item.username == username
        })
        if (!obj) {
            return {
                code: 201,
                msg: '账号不存在',
                data: null
            }
        } else if (obj.tel != phone) {
            return {
                code: 201,
                msg: '该账户绑定不是这个手机号',
                data: null
            }
        } else {
            LoginArr.forEach(item => {
                if (item.username == username && item.tel == phone) {
                    item.pwd = pwd
                    console.log(item);
                    return
                }
            })
            return {
                code: 200,
                msg: '密码修改成功',
                data: null
            }
        }
    }
}